package com.yanqu.road.server.logic.activity.condition.recharge;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;
import java.util.Date;

public class RechargeTenDayDiscountCondition extends BaseActivityCondition {

    public RechargeTenDayDiscountCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        //不从外面更新了
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.TenDayDiscount.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.TenDayDiscount.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        long beginTime = activityInfo.getBeginTime();
        //现在是活动的第几天 可以领取吗
        int i = DateHelper.calc2DateTDOADays(new Date(beginTime * DateHelper.SECOND_MILLIONS), new Date());
        //如果小于天数配置
        if (i < activityConditionInfo.getParamList().get(2).intValue()) {
            return false;
        }
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }
}
